<?php

namespace App\Http\Controllers;

use App\library\services\lib\FIleUploadService;
use App\library\services\lib\tencentCloud\Cos;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller as BaseController;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    /**
     * author:william
     * @param array $data
     * @return mixed
     */
    public function res($data = [])
    {
        if ($data['code'] == 200) {
            return $this->success($data['message'], $data['data'], $data['code']);
        }
        return $this->fail($data['message'], $data['data'], $data['code']);
    }

    /**
     * author:william
     * @param $msg
     * @param array $data
     * @param int $code
     * @return mixed
     */
    public function success($msg, $data = [], $code = 200)
    {
        return response()->json([
            'status' => true,
            'code' => $code,
            'message' => $msg,
            'data' => $data,
        ]);
    }

    /**
     * author:william
     * @param $msg
     * @param array $data
     * @param int $code
     * @return mixed
     */
    public function fail($msg, $data = [], $code = 501)
    {
        return response()->json([
            'status' => false,
            'code' => $code,
            'message' => $msg,
            'data' => $data,
        ]);
    }

    /**
     * Author:Zhongyuan Lu
     * 指定文件名上传腾讯云
     * @param $filename
     * @return mixed
     */
    public function linUIUploadFile($filename)
    {
        //扩展名
        $ext = substr($filename,strrpos($filename,'.')+1);
        return FIleUploadService::uploadFile($filename,$ext);
    }
}
